package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.ResetRadioGroupEvent;
	import com.tongji.housediy.events.commonEvent.ShowComplementInforEvent;
	import com.tongji.housediy.model.RightListStateModel;
	import com.tongji.housediy.utils.ShowCustomToolTip;
	
	import flash.events.MouseEvent;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class BuildingCompMediator extends Mediator
	{
		[Inject]
		public var view:BuildingComp;
		
		[Inject]
		public var model:RightListStateModel;
		
		override public function onRegister():void
		{
			view.roomBtn.addEventListener(MouseEvent.CLICK, roomBtnClickHandler);
			view.wallBtn.addEventListener(MouseEvent.CLICK, wallBtnClickHandler);
			view.doorBtn.addEventListener(MouseEvent.CLICK, doorBtnClickHandler);
			view.windowBtn.addEventListener(MouseEvent.CLICK, windowBtnClickHandler);
			view.floorBtn.addEventListener(MouseEvent.CLICK, floorBtnClickHandler);
			this.addContextListener(ShowComplementInforEvent.SHOW_COMPLEMENT_INFOR, showToolTip, ShowComplementInforEvent);
			this.addContextListener(ResetRadioGroupEvent.RESET_BUILDING_RADIO, resetRadioHandler, ResetRadioGroupEvent);
		}
		
		private function showToolTip(event:ShowComplementInforEvent):void
		{
			var showToolTip:ShowCustomToolTip = new ShowCustomToolTip(view.roomBtn, "请选择房间形状\n拖放至场景中");
			showToolTip = new ShowCustomToolTip(view.wallBtn, "改变结构\n进行房型的调整");
			showToolTip = new ShowCustomToolTip(view.doorBtn, "请选择合适的门\n拖放至任一墙上");
			showToolTip = new ShowCustomToolTip(view.windowBtn, "请选择合适的窗\n拖放至任一墙上");
			showToolTip = new ShowCustomToolTip(view.floorBtn, "选择地面材质\n拖至房间内，\n或自定义地面");
		}
		
		private function resetRadioHandler(event:ResetRadioGroupEvent):void
		{
			view.buildingGroup.selection = view.roomBtn;
		}
		
		private function roomBtnClickHandler(event:MouseEvent):void
		{
			model.stateIndex = 0;
			view.buildingGroup.selection = view.roomBtn;
		}
		
		private function wallBtnClickHandler(event:MouseEvent):void
		{
			model.stateIndex = 1;
			view.buildingGroup.selection = view.wallBtn;
		}
		
		private function doorBtnClickHandler(event:MouseEvent):void
		{
			model.stateIndex = 2;
			view.buildingGroup.selection = view.doorBtn;
		}
		
		private function windowBtnClickHandler(event:MouseEvent):void
		{
			model.stateIndex = 3;
			view.buildingGroup.selection = view.windowBtn;
		}
		
		private function floorBtnClickHandler(event:MouseEvent):void
		{
			model.stateIndex = 4;
			view.buildingGroup.selection = view.floorBtn;
		}
	}
}